package cn.org.zx.login.ctrl;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import cn.org.zx.common.aop.BeanFactory;
import cn.org.zx.common.commutils.CommMethod;
import cn.org.zx.common.commutils.Json;
import cn.org.zx.login.blh.LoginBlh;

public class LoginCtrl extends MultiActionController{
	private LoginBlh blh;
	
	public LoginCtrl(){
		blh = (LoginBlh)BeanFactory.getBean(new LoginBlh());
	}
			
	//后台用户登录
	public ModelAndView getLogin_M(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		String strip = request.getRemoteAddr();
		Map mapData = request.getParameterMap();
		
		HttpSession getsession = request.getSession();
		String strRankCode = CommMethod.strDealNull(getsession.getAttribute("randImage").toString());
		
		Map mapReturn = blh.getLogin_M(mapData,strip,strRankCode);
		//System.out.println("loginsystem="+mapReturn);
		if(!mapReturn.isEmpty()){
			HttpSession session = request.getSession();			
			session.setAttribute("infodata", mapReturn);
		}
		
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String result = Json.toJson(mapReturn);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;			
	}
}
